/*
 * @lc app=leetcode.cn id=696 lang=javascript
 *
 * [696] 计数二进制子串
 */

// @lc code=start
/**
 * @param {string} s
 * @return {number}
 */
var countBinarySubstrings = function(s) {
    let i=0
    let res=[],count=1,sum=0
    while(i<s.length-1){
        j=i+1
        if(s[i]==s[j])count++
        else{
            res.push(count)
            count=1
        }
        i++
    }
    res.push(count)
    for(let i=0;i<res.length-1;i++){
        sum+=Math.min(res[i],res[i+1])
    }
    return sum
};
// @lc code=end
console.log(countBinarySubstrings("10001000"))
